package com.sfx.算法专题.双指针.同向双指针.普通双指针;

/**
 * Created with IntelliJ IDEA.
 * Description:https://leetcode.cn/problems/compare-version-numbers/description/
 * User: sfx
 * Date: 2023-07-18
 * Time: 12:23
 */
public class Code_1_compareVersion {

   static class Solution {
        public int compareVersion(String version1, String version2) {
            //思路：将两个字符串进行分割，然后通过parseInt进行转数字比较
            String[] s1 = version1.split("\\.");
            String[] s2 = version2.split("\\.");
            int index1 = 0;
            int index2 = 0;
            int len1 = s1.length;
            int len2 = s2.length;
            while(index1<len1||index2<len2) {
                int a =0;
                int b =0;
                if(index1<len1){
                    a = Integer.parseInt(s1[index1++]);
                }
                if(index2<len2){
                    b = Integer.parseInt(s2[index2++]);
                }
                if(a!=b){
                    return a>b?1:-1;
                }
            }
            return 0;
        }
    }
}
